package com.ltu.ai.sparkdesk.websocket.iat;

import java.util.Arrays;

import com.google.gson.JsonObject;


public  class ResponseIatData {
    private int code;
    private String message;
    private String sid;
    private Data data;
    public int getCode() {
        return code;
    }
    public String getMessage() {
        return this.message;
    }
    public String getSid() {
        return sid;
    }
    public Data getData() {
        return data;
    }

public static class Data {
    private int status;
    private Result result;
    public int getStatus() {
        return status;
    }
    public Result getResult() {
        return result;
    }
}
public static  class Result {
    int bg;
    int ed;
    String pgs;
    int[] rg;
    int sn;
    Ws[] ws;
    boolean ls;
    JsonObject vad;
    public  Text getText() {
        Text text = new Text();
        StringBuilder sb = new StringBuilder();
        for (Ws ws : this.ws) {
            sb.append(ws.cw[0].w);
        }
        text.sn = this.sn;
        text.text = sb.toString();
        text.sn = this.sn;
        text.rg = this.rg;
        text.pgs = this.pgs;
        text.bg = this.bg;
        text.ed = this.ed;
        text.ls = this.ls;
        text.vad = this.vad==null ? null : this.vad;
        return text;
    }
}
public static class Ws {
    Cw[] cw;
    int bg;
    int ed;
}
public static class Cw {
    int sc;
    String w;
}
public static class Text {
    int sn;
    int bg;
    int ed;
    String text;
    String pgs;
    int[] rg;
    boolean deleted;
    boolean ls;
    JsonObject vad;
    @Override
    public String toString() {
        return "Text{" +
                "bg=" + bg +
                ", ed=" + ed +
                ", ls=" + ls +
                ", sn=" + sn +
                ", text='" + text + '\'' +
                ", pgs=" + pgs +
                ", rg=" + Arrays.toString(rg) +
                ", deleted=" + deleted +
                ", vad=" + (vad==null ? "null" : vad.getAsJsonArray("ws").toString()) +
                '}';
    }
}
//解析返回数据，仅供参考
public static  class Decoder {
    private Text[] texts;
    private int defc = 10;
    public Decoder() {
        this.texts = new Text[this.defc];
    }
    public  void decode(Text text) {
        if (text.sn >= this.defc) {
            this.resize();
        }
        if ("rpl".equals(text.pgs)) {
            for (int i = text.rg[0]; i <= text.rg[1]; i++) {
                this.texts[i].deleted = true;
            }
        }
        this.texts[text.sn] = text;
    }
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (Text t : this.texts) {
            if (t != null && !t.deleted) {
                sb.append(t.text);
            }
        }
        return sb.toString();
    }
    public void resize() {
        int oc = this.defc;
        this.defc <<= 1;
        Text[] old = this.texts;
        this.texts = new Text[this.defc];
        for (int i = 0; i < oc; i++) {
            this.texts[i] = old[i];
        }
    }
    public void discard(){
        for(int i=0;i<this.texts.length;i++){
            this.texts[i]= null;
        }
    }
	}
}
